function ByWebSocket(contextPath,action) {
	var websocket;
    var host=(window.location.protocol == 'http:') ? 'ws://' : 'wss://' ;  
    host += window.location.host + contextPath; 
	if ('WebSocket' in window) {
		websocket = new WebSocket(host +"/ws/"+action);
	} else if ('MozWebSocket' in window) {
		websocket = new MozWebSocket(host +"/ws/"+ action);
	} else {
		var options = {protocols_whitelist: ["websocket", "xhr-streaming", "xdr-streaming", "xhr-polling", "xdr-polling", "iframe-htmlfile", "iframe-eventsource", "iframe-xhr-polling"], debug: true}; 
		websocket = new SockJS("http://"+window.location.host + contextPath+"/ws/sockjs/"+action,options);
	}
	return websocket;
}

function canBuy() {
	var isCan = false;
	$.ajax({
		url:"checkCanBuy.action",
		async:false,
		cache:false,
		dataType:"json",
		success:function(response) {
		$("#checkMsg").toggleClass("hide");
			if(response.dataCode.code == "0") {
				isCan = true;
			}else if(response.dataCode.code == "-4") {
				isCan = false;
				alert(response.dataCode.message);
			}else {
				isCan = false;
				if(response.data!=undefined&&response.data!=null){
					var s = "";
					for(var i=0;i<response.data.length;i++) {
						s += response.data[i] + "\n";
					}
					alert(s);
				}else{
					alert(response.dataCode.message);
				}
			}
		},
		error:function(xhr,errinfo,o) {
			alert("閿欒:"+errinfo)
			isCan = false;
		},
		timeout:30000,
		type:"get"
	});		
	return isCan;
}	

//鍟嗗搧璇︽儏鏄惁鍙崠
function gdcanBuy(spdm,spmc) {
	var isCan = false;
	$.ajax({
		url:"checkCanBuy.action",
		async:false,
		cache:false,
		dataType:"json",
		success:function(response) {
		$("#checkMsg").toggleClass("hide");
			if(response.dataCode.code == "0") {
				isCan = true;
			}else if(response.dataCode.code == "-4") {
				isCan = false;
				alert(response.dataCode.message);
			}else {
				isCan = false;
				var s = "";
				for(var i=0;i<response.data.length;i++) {
					s += response.data[i] + "\n";
				}
				alert(s);
			}
		},
		error:function(xhr,errinfo,o) {
			alert("閿欒:"+errinfo)
			isCan = false;
		},
		timeout:30000,
		type:"get",
		data:{gdspdm:spdm,gdspmc:spmc}
	});		
	return isCan;
}	